package com.company;

import java.util.ArrayList;

/**
 * Created by phazel on 12/04/14.
 */
public class PrimeFactors
{
    public ArrayList<Integer> generate( int n )
    {
        ArrayList<Integer> factors = new ArrayList<Integer>();

        for(int i = 2; i <= n; i++)
        {
            if( isPrime( i ) && n % i == 0 )
            {
                factors.add( i );
            }
        }

        return factors;
    }

    private boolean isPrime( int n )
    {
        boolean prime = true;

        for (int i = 2; i <= n/2; i++)
        {
            if(n % i == 0)
            {
                prime = false;
                break;
            }
        }

        return prime;
    }
}
